import unittest
# from api.orderApi import OrderApi
from api.apifactory import ApiFactory
from analysis_data2 import AnalysisData
from parameterized import parameterized


class TestOrder(unittest.TestCase):
    @parameterized.expand(
        AnalysisData.get_json_data("order.json", "creat_order", ["creat_code", "creat_length", "creat_pass"]))
    def test01_Create(self, creat_code, creat_length, creat_pass):
        # creat_code = 200
        # creat_length = 0
        # creat_pass = True
        response = ApiFactory.order_api().creatApi(2, 1)
        print(response.json())
        self.assertEqual(response.status_code, creat_code)
        self.assertTrue(len(response.json()) > creat_length)
        self.assertTrue(len(response.json().get("order_no")) > creat_length)
        self.assertTrue(len(response.json().get("order_id")) > creat_length)
        self.assertEqual(response.json().get("pass"), creat_pass)

    @parameterized.expand(AnalysisData.get_json_data("order.json", "check_order",
                                                     ["check_code", "check_length", "check_id", "check_order_no",
                                                      "check_price"]))
    def test02_check(self, check_code, check_length, check_id, check_order_no, check_price):
        # check_code = 200
        # check_length = 0
        # check_id = 103
        # check_order_no = "DC20658727747527"
        # check_price = "0.01"
        response = ApiFactory.order_api().checkApi(check_id)
        print(response.json())
        self.assertEqual(response.status_code, check_code)
        self.assertTrue(len(response.json()) > check_length)
        self.assertEqual(response.json().get("id"), check_id)
        self.assertEqual(response.json().get("order_no"), check_order_no)
        self.assertEqual(response.json().get("total_price"), check_price)

    @parameterized.expand(
        AnalysisData.get_json_data("order.json", "get_order", ["get_code", "get_length", "get_page", "get_list"]))
    def test03_get(self, get_code, get_length, get_page, get_list):
        # get_code = 200
        # get_length = 0
        # get_page = 1
        # get_list = ["id", "order_no", "total_price"]
        response = ApiFactory.order_api().getApi()
        print(response.json())
        self.assertTrue(response.status_code, get_code)
        self.assertTrue(len(response.json()) > get_length)
        self.assertTrue(response.json().get("current_page"), get_page)
        for i in get_list:
            self.assertTrue(i in response.text)
